{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
	<form class="layui-form gg-form-bar border-x border-t">
		<div class="layui-input-inline" style="width:200px;">
			<input type="text" name="keywords" placeholder="输入关键字" class="layui-input" autocomplete="off" />
		</div>
		<div class="layui-input-inline" style="width:120px;">
			<select name="stage">
            <option value="">当前阶段</option>
            {volist name=":trace_stage()" id="v"}
            <option value="{$key}">{$v}</option>
            {/volist}
          </select>
		</div>
		<div class="layui-input-inline" style="width:300px;">
			<input type="text" class="layui-input" id="diff_time" placeholder="预计签单时间" readonly name="diff_time">
		</div>
		<div class="layui-input-inline" style="width:120px;">
			<input type="text" name="username" placeholder="请选择归属人" class="layui-input picker-one" autocomplete="off" />
			<input type="text" name="uid" style="display:none" />
		</div>
		<div class="layui-input-inline" style="width:150px;">
			<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform"><i class="layui-icon layui-icon-search mr-1"></i>搜索</button>
			<button type="reset" class="layui-btn layui-btn-reset" lay-filter="reset">清空</button>
		</div>
	</form>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
	<script>
	const moduleInit = ['tool','employeepicker','laydatePlus'];
	function gouguInit() {
		var table = layui.table, tool = layui.tool, form = layui.form,laydatePlus=layui.laydatePlus;
		//日期范围
		var diff_time = new laydatePlus({'target':'diff_time'});
		layui.pageTable = table.render({
			elem: '#test'
			,toolbar: '#toolbarDemo'
			,title:'跟进记录列表'
			,url: "/customer/trace/index"
			,cellMinWidth: 80
			,page: true //开启分页
			,limit: 20
			,cols:  [[
					{field: 'id', title: '编号', width: 80, align: 'center'}
					,{field:'admin_name',title: '跟进人',align:'center',width: 80}
					,{field:'follow_time',title: '跟进日期',align:'center',width: 128}
					,{field:'hours',title: '跟进时长',align:'center',width: 80}
					,{field:'type_name',title: '跟进方式',width: 80, align: 'center',templet:function(d){
						var html = '<span class="layui-color-'+d.type+'">'+d.type_name+'</span>';
						return html;
					}}
					,{field:'content',title: '沟通内容'}
					, { field: 'chance', title: '关联销售机会『跟进阶段』', width: 200,templet:function(d){
							var html = '-';
						if(d.chance_id>0){
							html = d.chance+'『'+d.stage_name+'』';
						}
						return html;
					}}
					,{field:'next_time',title: '下次跟进时间', align:'center',width: 128}
					,{fixed:'right',width:132,title: '操作', align:'center',templet: function(d){
							var html = '<div class="layui-btn-group">';
							var btn='<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>';
							var btn1='<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="view">详情</a>';
							var btn2='<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>';
							return html+btn+btn1+btn2+'</div>';
					}}			
				]]
			});
			
			table.on('tool(test)', function(obj){
				var data = obj.data; //获得当前行数据
				var layEvent = obj.event;		 
				if(layEvent === 'edit'){ //编辑
					let url = '/customer/api/add_trace/id/'+data.id;
					tool.side(url);
				}
				if(layEvent === 'view'){ //查看
					let url = '/customer/api/view_trace/id/'+data.id;
					tool.side(url);
				}
				if(layEvent === 'del'){ //删除
					layer.confirm('确定要删除该跟进记录吗?', {icon: 3, title:'提示'}, function(index){
						let callback = function (e) {
							layer.msg(e.msg);
							if (e.code == 0) {
								layui.pageTable.reload();
							}
						}
						tool.delete('/customer/api/del_trace',{'id':data.id},callback);
						layer.close(index);
					});
				}
				return false;
			})
			
			//监听搜索提交
			form.on('submit(webform)', function(data) {
				layui.pageTable.reload({
					where: data.field,
					page: {curr: 1}
				});
				return false;
			});
		}
	</script>
{/block}
<!-- /脚本 -->